package com.engine.jucailinkq.attendance.component.calendarscheduling.web;

import com.engine.jucailinkq.attendance.component.calendarscheduling.service.WorkRulesService;
import com.engine.jucailinkq.attendance.component.calendarscheduling.service.impl.WorkRulesServiceImpl;
import com.engine.common.util.ParamUtil;
import com.engine.jucailinkq.common.util.ResponseResult;
import com.engine.common.util.ServiceUtil;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.ws.rs.POST;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * 日历排班
 * @Author liang.cheng
 * @Date 2023/12/26 6:52 PM
 * @Description: TODO
 * @Version 1.0
 */
public class WorkRulesController {

    private WorkRulesService getReportCollectService(User user) {
        return ServiceUtil.getService(WorkRulesServiceImpl.class,user);
    }


    @GET
    @Path("/list")
    @Produces(MediaType.APPLICATION_JSON)
    public String getWorkRulesList(@Context HttpServletRequest request, @Context HttpServletResponse response,
                                    @QueryParam("resourceIds") String resourceIds) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, Map<String, Object>>(user).run(getReportCollectService(user) :: getWorkRulesList,resourceIds);
    }

    @GET
    @Path("/queryDepartSchedule")
    @Produces(MediaType.APPLICATION_JSON)
    public String getDepartSchedule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String,Object> paramMap = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getReportCollectService(user) :: getDepartSchedule,paramMap);
    }

    @POST
    @Path("/saveCalendarWork")
    @Produces(MediaType.APPLICATION_JSON)
    public String saveCalendarWork(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String,Object> paramMap = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getReportCollectService(user) :: saveCalendarWork,paramMap);
    }

    @POST
    @Path("/queryDefaultCalendar")
    @Produces(MediaType.APPLICATION_JSON)
    public String queryDefaultCalendar(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String,Object> paramMap = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getReportCollectService(user) :: queryDefaultCalendar,paramMap);
    }
}
